<template>
 <div style="width:80%">
    <h1>登录</h1>
    <el-divider></el-divider>
    <el-form  label-width="auto" style="max-width: 1000px">
        <el-form-item label="用户名">
           <el-input v-model="loginName" />
        </el-form-item>
        <el-form-item label="密码">
           <el-input type="password" v-model="loginPwd" />
        </el-form-item>
       <el-form-item>
           <el-button type="primary" @click="login">登录</el-button>
           <el-button>取消</el-button>
        </el-form-item>
  </el-form>

  </div>
</template>

<script>
import axios from '@/axios/index.js';
import {useUserStore} from '../stores/userStore.js';
export default {
   data(){
      return {
             loginPwd:'',
             loginName:'',
             store:useUserStore()
          }
      }
   ,
   methods:{
      login:function(){
        axios.post("http://localhost:81/my/ajax/login"
           ,"loginName="+this.loginName+"&loginPwd="+this.loginPwd)
        .then((resp)=>{
               //alert(resp.data.state);
               if(resp.data.state==2000){
                  let user=resp.data.data;
                  this.store.login(user);
                  // this.store.saveUser(user);
                  // sessionStorage.setItem("curUser",JSON.stringify(user));
                  this.$router.push("/home");
                }
               // else{
               //    alert("发生错误"+resp.data.msg);
               // }
        });
        //.catch((err)=>{alert(err);})

      }
   }
}
</script>

<style scoped>
   
</style>